<script src="../js/Calendar.js"></script>
<script src="../js/global/Date_func.js"></script>
<script src="http://www.12301.cc/admin/js/orderReport.js"></script>
<link rel="stylesheet" type="text/css" href="../css/select2.css">
<link rel="stylesheet" type="text/css" href="http://www.12301.cc/admin/css/orderReport.css">
<link rel="stylesheet" type="text/css" href="../css/member.css"/>
<style>
	.report{overflow: hidden;margin:10px 0; padding:15px; border:1px solid #eee; }
	.report span.part{ margin-right:20px;}
	input.time{    background: url("../images/rili.png") no-repeat scroll right center #FFFFFF;
    border: 1px solid #7F9DB9;
    height: 20px;
    line-height: 20px;
    width: 120px;}
	.total{ width:100%; text-align:center;}
	input.checkbox{ vertical-align:-2px; margin-right:2px;}
	.btn{ background:#eee; padding:4px 15px; *padding:4px 8px; background:url("../images/mc_title.png") no-repeat right top; color:#fff; border:none; cursor:pointer}
	#excel{margin-left:10px;}
</style>
<h3 class="mc_title">
	<span class="mctit_1 ">
		<a href="orderReport.html"><span class="mctit_2">已卖出产品报表</span></a>
	</span>
    <span class="mctit_1 notcur">
		<a href="orderReport_2.php"><span class="mctit_2">超详细版已卖出产品报表</span></a>
	</span>
</h3>
<form class="report" method="get">
	<input type="hidden" name="proList" value='<?=$proList?>'/>
	<input type="hidden" name="act" id="act" value=""/>
	<p>
		<span class="part">
			<label>
                <!--交易日期：-->
                <select name="time_type" id="time_type">
                    <option value="1" <?=$_REQUEST['time_type']==1?'selected' :''?>>下单时间</option>
                    <option value="2" <?=$_REQUEST['time_type']==2?'selected' :''?>>预计游玩</option>
                    <option value="3" <?=$_REQUEST['time_type']==3?'selected' :''?>>完成时间</option>
                </select>
            </label>
			<input type="text" name="begintime" id="begintime" class="time" value="<?=$btime?>" onmouseup="SelectDate(this,'yyyy-MM-dd',0,0)"/>
			<label>至</label>
			<input type="text" name="endtime" id="endtime" class="time" value="<?=$etime?>" onmouseup="SelectDate(this,'yyyy-MM-dd',0,0)"/>
			<a href="javascript:changeDate('today');" class="sDate">今天</a>
			<a href="javascript:changeDate('yesterday');" class="sDate">昨天</a>
			<a href="javascript:changeDate('week');" class="sDate">本周</a>
			<a href="javascript:changeDate('lastweek');" class="sDate">上周</a>
			<a href="javascript:changeDate('month');" class="sDate">本月</a>
			<a href="javascript:changeDate('lastmonth');" class="sDate">上月</a>
		</span>
		<input type="submit" class="btn" value="查 询"/>
		<input type="button" id="excel" class="btn" value="导 出" onclick="tableToExcel('testTable', 'W3C Example Table')" value="导出到Excel"/>
	</p>
	<p style="margin:10px 0;">
	订单状态：
	<span  class="part">
	<?$_REQUEST['status'] = is_array($_REQUEST['status'])?$_REQUEST['status']:array();?>
		<input class="checkbox" type="checkbox" name="status[]" <?=in_array("0|1|2|3|5|6|7",$_REQUEST['status'])?"checked":""?> value="0|1|2|3|5|6|7"/><label>全部</label>
		<input class="checkbox" type="checkbox" name="status[]" <?=in_array("0|6",$_REQUEST['status'])?"checked":""?> value="0|6"/><label>未使用</label>
		<input class="checkbox" type="checkbox" name="status[]" <?=(in_array("1",$_REQUEST['status']) ||$_REQUEST['time_type']==3)?"checked":""?> value="1"/><label>已使用</label>
		<input class="checkbox" type="checkbox" name="status[]" <?=(in_array("2",$_REQUEST['status'])&& $_REQUEST['time_type']!=3)?"checked":""?> value="2"/><label>已过期</label>
		<input class="checkbox" type="checkbox" name="status[]" <?=(in_array("3|5",$_REQUEST['status']) && $_REQUEST['time_type']!=3)?"checked":""?> value="3|5"/><label>已取消</label>
	<!----><input class="checkbox" value="1" type="checkbox" name="Order_Globle_Search_c" <?if($_GET['Order_Globle_Search_c']) echo "checked=true"?>>是否只统计订单量,票数,金额</input>
	</span>
	<span  class="part">
		统计方式：
		<select name="by" <?if($_GET['Order_Globle_Search_c']=='1') echo 'disabled=true';?>>
			<option value="lid" <?=($_REQUEST['by']=="lid")?"selected":""?>>按景区统计</option>
			<option value="tid" <?=($_REQUEST['by']=="tid")?"selected":""?>>按门票统计</option>
            <option value="aid" <?=($_REQUEST['by']=="aid")?"selected":""?>>按供应商统计</option>
			<option value="mid" <?=($_REQUEST['by']=="mid")?"selected":""?>>按分销商统计</option>
		</select>
	</span>
	</p>
	<span  class="">
		统计范围：
		<select name="select_range" class="select_range" <?if($_GET['Order_Globle_Search_c']=='1') echo 'disabled=true';?>>
			<option value="0" >还是原来的统计方式</option>
			<option value="1" <?if($_GET['select_range']=='1') echo 'selected="selected"';?>>只统计景区最初供应商的订单量</option>
            <option value="2" <?if($_GET['select_range']=='2') echo 'selected="selected"';?>>统计这个供应商所经手的订单量</option>
		</select>
	</span>
    <p style="margin:10px 0;">
		<span  class="part">
            景点：
            <span class="searchSuggest">
                <?
                if($_GET['landid']){
                    $_GET['landid'] = $_GET['landid']+0;
                    $sel_land = "select title,id from uu_land where id={$_GET['landid']} limit 1";
                    $GLOBALS['le']->query($sel_land);
                    $row_s_land=$GLOBALS['le']->fetch_assoc();
                }
                ?>
                <input type="text" class="suggest_input" id="land_a" autocomplete="off" value="<?=$row_s_land['title'] ? $row_s_land['title']:点击搜索景区?>" onfocus="if (value =='点击搜索景区'){value =''}" onblur="if (value ==''){value='点击搜索景区'}"/>
		
                <input type="hidden" name="landid"   class="liid" value="<?=$_GET['landid']?>"/>
                <input type="hidden"  class="lid_id" value="0"/>
                <ul class="suggest_ul">
                </ul>
        </span>
        <span class="part">
            过滤条件: <select name="is_test">
                <option value="2" <?=$_GET['is_test']==2?'selected':''?>>非测试帐号</option>
                <option value="1" <?=$_GET['is_test']==1?'selected':''?>>测试帐号</option>
				
            </select>
	
        </span>
    </p>
    <p style="margin:10px 0;">
		<span  class="part">
            门票：
            <select name="ticket" id="ticket">
                <option value="">--选择--</option>
				<?
					if(isset($_REQUEST['landid']) && !empty($_REQUEST['landid'])){
						$sql='SELECT id,title FROM uu_jq_ticket WHERE landid='.($_REQUEST['landid']+0);//
						$GLOBALS['le']->query($sql);
						$tickes = array();
						while($row=$GLOBALS['le']->fetch_assoc()){
							$tickes[]=$row;
						}
						if(count($tickes)){
							$html = '';
							foreach($tickes as $v){
							
								$title= $v['title'];
								$vs=$v['id'].'_'.$title;
								if(isset($_REQUEST['ticket']) && !empty($_REQUEST['ticket']) && $_REQUEST['ticket']==$vs){
									$html.="<option value='{$vs}' selected='selected'>{$title}</option>";
								}else{
									$html.="<option value='{$vs}'>{$title}</option>";
								}
							}
							echo $html;
						}
					}
				?>
            </select>
        </span>
    </p>
    <p style="margin:10px 0;">
        <span  class="part">分销商：
			<span class="searchSuggest">
                        <?
                        if($fid){
                            $fid = $fid+0;
                            $sel_supplier = "select dname,id from pft_member where id={$fid} limit 1";
                            $GLOBALS['le']->query($sel_supplier);
                            $row_a_dname=$GLOBALS['le']->fetch_assoc();
                        }
                        ?>
						<input type="text" name="fid_str" class="suggest_input_fid" autocomplete="off" value="<?=$row_a_dname['dname'] ? $row_a_dname['dname']:点击搜索分销商?>" onfocus="if (value =='点击搜索分销商'){value =''}" onblur="if (value ==''){value='点击搜索分销商'}"/>
<!--                        <span style="color: red">如果供应商和分销商都不填的话,查出来的数据是包含转分销的</span>-->
						<input type="hidden" name="fid" id="land"  class="liid_fid" value="<?=$_GET['fid']?>"/>
						<input type="hidden"  class="lid_id_fid" value="1"/>
						<ul class="suggest_ul_fid">
						</ul>
					</span>
        </span>
    </p>
    <p style="margin:10px 0;">
        <span  class="part">供应商：
       <?//=GetHtmlSelect($seller, 'aid', $aid, array('k'=>0,'v'=>'--供应商--'))?>
      
			<span class="searchSuggest">
                        <?
                        if($aid){
                            $aid = $aid;
                            $sel_supplier = "select dname,id from pft_member where id={$aid} limit 1";
                            $GLOBALS['le']->query($sel_supplier);
                            $row_s_dname=$GLOBALS['le']->fetch_assoc();
                        }
                        ?>
						<input type="text" name="aid_str" class="suggest_input_aid" autocomplete="off" value="<?=$row_s_dname['dname'] ? $row_s_dname['dname']:点击搜索供应商?>" onfocus="if (value =='点击搜索供应商'){value =''}" onblur="if (value ==''){value='点击搜索供应商'}"/>
						<input type="hidden" name="aid" id="land"  class="liid_aid" value="<?=$_GET['aid']?>"/>
						<input type="hidden"  class="lid_id_aid" value="0"/>
						<ul class="suggest_ul_aid">
						</ul>
					</span>
              
        </span>

    </p>
</form>
<?

?>
<div class="rank">
	<div class="rankcon">
		<table class="ranktab" id="testTable">
			<thead id="rankhd">
				<th>序号</th>
                <?
//                    $n=2;
                if($by=='lid'){
//                    $n=3;
//                    ?>
                <th>景区ID</th>
                <?}?>
				<th class="tL"><?=$titleT[$by]?></th>
				<th><span class="sort" onclick="sortTable('offmain',<?=$n?>, true ,this);">订单数量</span></th>
				<th><span class="sort" onclick="sortTable('offmain',<?=$n+1?>, true ,this);">门票数量</span></th>
				<th><span class="sort" onclick="sortTable('offmain',<?=$n+2?>, true ,this);">金额</span></th>
				<th><span class="sort" onclick="sortTable('offmain',<?=$n+3?>, true ,this);">余额支付</span></th>
				<th><span class="sort" onclick="sortTable('offmain',<?=$n+4?>, true ,this);">在线支付</span></th>
				<th><span class="sort" onclick="sortTable('offmain',<?=$n+5?>, true ,this);">授信支付</span></th>
				<th><span class="sort" onclick="sortTable('offmain',<?=$n+6?>, true ,this);">产品自销</span></th>
				<th><span class="sort" onclick="sortTable('offmain',<?=$n+7?>, true ,this);">现场支付</span></th>
			</thead>
			<tbody id="offmain">

				<?
                if(is_array($r))
                foreach($r as $lid=>$row){
					$totals['order']+=$row['order'];
					$totals['tnum']+=$row['tnum'];
					$totals['money']+=$row['money'];
					$totals['pmode0']+=$row['pmode0'];
                    $online_money = $row['pmode1']+$row['pmode5']+$row['pmode6']+$row['pmode7'];
					$totals['pmode1']+=$online_money;
					$totals['pmode2']+=$row['pmode2'];
					$totals['pmode3']+=$row['pmode3'];
					$totals['pmode4']+=$row['pmode4'];
				?>
				<tr data-id="">
					<td><?=++$n?></td>
                    <?if($by=='lid'){?>
                    <td><?=$lid?></td>
                    <?}?>
					<td class="tL"><?=$row['title']?></td>
					<td><?=$row['order']?></td>
					<td><?=$row['tnum']?></td>
					<td><?=$row['money']/100?>元</td>
					<td><?=$row['pmode0']/100?></td>
					<td><?=$online_money/100?></td>
					<td><?=$row['pmode2']/100?></td>
					<td><?=$row['pmode3']/100?></td>
					<td><?=$row['pmode4']/100?></td>
				</tr>
				<?}?>
			</tbody>
			<tfoot>
			<?php if(count($r)>0):?>
				<tr>
					<td  colspan="2">总计：</td>
                    <?if($by=='lid'){?>
                        <td></td>
                    <?}?>
					<td><?=$totals['order']?></td>
					<td><?=$totals['tnum']?></td>
					<td><?=$totals['money']/100?></td>
					<td><?=$totals['pmode0']/100?></td>
					<td><?=$totals['pmode1']/100?></td>
					<td><?=$totals['pmode2']/100?></td>
					<td><?=$totals['pmode3']/100?></td>
					<td><?=$totals['pmode4']/100?></td>
				</tr>
			<?php else:?>
				<tr>
					<td align="left" colspan="9">&nbsp;&nbsp;&nbsp;交易日期无销售订单！</td>
				</tr>
			<?php endif;?>
			</tfoot>
		</table>
	</div>
</div>
<script src="../js/jsorder.js"></script>
<script>
	$("#time").change(function(){
		Date_func.selectDate($(this).val(),$("#begintime").get(0),$("#endtime").get(0));
	});
	$("input.btn").click(function(){
		var btime=$("#begintime").val();
		var etime=$("#endtime").val();
		btime=btime.split("-");
		etime=etime.split("-");
		month=(etime[0]-btime[0])*12+(etime[1]-btime[1]);
		if(month>3){
			//alert("交易日期时间间隔不能超过三个月");
			//return false;
		}
	});
	// 获取门票
	$(function(){ 
		$('#land_a').bind({ 
		onblur:function(){ 
		landid=$(this).val();
		$.ajax({
			uri:window.location.href,
			data:"landid="+landid,
			beforeSend:function (XMLHttpRequest) {
				XMLHttpRequest.setRequestHeader("request_type","getTicket");
			},
			success: function(data){
				data = JSON.parse(data);
				if(data.s=='success'){
					_options = '<option value="">--选择--</option>';
					for(var i in data.content){
						_options+='<option value="'+data.content[i].id+'_'+data.content[i].title+'">'+data.content[i].title+'</option>';
					}
					$("#ticket").html(_options);

				}
			}
		});
		}
		})
		})
	

    var tableToExcel = (function() {
        var uri = 'data:application/vnd.ms-excel;base64,'
            , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
            , base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
            , format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
        return function(table, name) {
            if (!table.nodeType) table = document.getElementById(table)
            var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
            window.location.href = uri + base64(format(template, ctx))
        }
    })()

  function changeDate(date){
        // lastweek颠倒了
     if(date=='lastweek'){
            Date_func.selectDate(date,$("#begintime").get(0),$("#endtime").get(0));
        }
     if(date!='lastweek'){
        Date_func.selectDate(date,$("#begintime").get(0),$("#endtime").get(0));
     }
    }

	 $('.select_range[name=select_range]').change(function(){
        var i=$(".select_range").get(0).selectedIndex;
		if(i==0){
			$(".suggest_input_fid").attr("disabled",false);
			$(".suggest_input_aid").attr("disabled",false);
		}	
		if(i==1){
			$(".suggest_input_fid").attr("disabled",true);
			$(".suggest_input_aid").attr("disabled",true);
		}
		if(i==2){
			$(".suggest_input_fid").attr("disabled",true);
			$(".suggest_input_aid").attr("disabled",false);
		}  
    });

    $('input:[name=Order_Globle_Search_c]').change(function(){
        if($(this).attr('checked')=='checked'){
            $('.select_range option:first').attr('selected',true);
            $(".select_range").attr("disabled",true);
            $("select:[name=by]").attr("disabled",true);
            $(".suggest_input_fid").attr("disabled",false);
            $(".suggest_input_aid").attr("disabled",false);
        }else{
            $(".select_range").attr("disabled",false);
            $("input:[name=by]").attr("disabled",false);
        }
    })
	

</script>




